home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Digital Sound Sample Playback and Manipulation System
- -----------------------------------------------------
-
-
- Version 2.0 Rowan McKenzie 28/3/89
-
-
- (C) Copyright 1989 by Rowan McKenzie
-
- You may copy these files or use the source code only
- for non-profit purposes. Please contact me if you wish to use any
- part of the package for commercial purposes.
- I accept no responsibility for any injury or damage
- caused by the use of any of these files.
-
-
-
-
- SAMPLER/PWMSAMPL is true public domain. In other words, I ask for no
- payment, registration fee, donations.... But please distribute these files
- in the form you found them. Also I would appreciate acknowledgment in any
- programs which use sections of my source code.
-
-
-
-
- Introduction
- ------------
-
-
- SAMPLER and PWMSAMPL are packages for playing and
- manipulating digitised sound samples. SAMPLER expects an 8 bit D/A
- converter to be available on a parallel printer port, while PWMSAMPL will
- play sounds on the PC speaker using pulse width modulation. Of course the
- quality of sound will be much better for the D/A version, however the PWM
- version requires no additional hardware.
-
- Support is provided for playing Pianoman .MUS files as songs using the
- current sampled sound.
-
-
-
- Hardware Requirements
- ---------------------
-
- PWMSAMPL requires:
-
- IBM XT/AT or close compatible
-
- Hercules, CGA or EGA graphics card
-
-
- SAMPLER requires in addition to the above:
-
- An 8 bit D/A converter connected to a parallel
- printer port
-
- If the sampling feature is to be used, a fast 8
- bit a/d converter is required (although the source
- code will probably need to modified for your
- setup).
-
-
- Software Requirements
- ---------------------
-
- MSDOS Ver 2.00 or later
-
- Pianoman program and support files (PCblue Vol
- 216, PCsig Vol 279) if the song mode is to used
-
-
-
-
- Background
- ----------
-
- SAMPLER and PWMSAMPL were derived from an A/D, D/A sound sampling
- system I wrote for an old CPM computer system.
-
- The pulse width modulation code uses the 8253 timer chip in one shot
- mode to drive the PC speaker with variable length pulses at a rate of
- about 20kHz. Varying the pulse length produces the same result as varying
- the voltage on a linearly controlled speaker. Unfortunately, the software
- overhead for this could mean that slow XT systems may not be fast enough to
- run PWMSAMPL. Also the sound volume is quite low (it's limited by the
- difference between the shortest and longest pulses used, which is limited
- by the sample rate, which is 20kHz for reasonable quality), so you will
- need to listen in a quiet room, or else build a D/A converter for SAMPLER !
-
- If you are interested in building a D/A converter to hear the much
- better sound quality of SAMPLER, a standard R-2R resistor ladder (R ~ 10k)
- into an amplifier of reasonably high input impedance (or low impedance via
- a 100k resistor) will be quite adequate. Alternatively, an active circuit
- using a chip such as the DAC0800 with its own power supply could be built.
- The circuit shown below worked adequately for me.
-
-
- D7 --- 20k ---+--- 200k -----> to amplifier
- |
- 10k
- |
- D6 --- 20k ---+
- |
- 10k
- |
- D5 --- 20k ---+
- p |
- r
- i etc ...
- n
- t |
- e 10k
- r |
- D0 --- 20k ---+
- |
- 20k
- |
- =============== gnd
-
-
-
- To utilise the sampling feature, a fast (at least 20kHz conversion
- rate) A/D converter must be available. My converter was designed to begin a
- conversion following a CPU access. As long as samples are taken at regular
- intervals, this technique minimises I/O overheads. The converter is
- addressed at the same location as the D/A converter to simplify the code.
- If your converter doesn't meet these specifications (probably won't), then
- the assembler code will require modification. SAMPLER is written in Turbo
- Pascal Version 5, and the font and driver units can only be used with that
- compiler.
-
-
-
-
- Using SAMPLER / PWMSAMPL
- ------------------------
-
- Version 2.0 of SAMPLER now uses mouse control rather than cumbersome
- keyboard commands. It is therefore necessary to have an MSMOUSE (R) driver
- installed before starting the program. Most mouse packages come with an
- MSMOUSE compatible driver and either two or three button mouses will work
- fine. If a mouse is unavailable, the cursor keys provide mouse emulation,
- although this makes controlling SAMPLER more difficult.
-
- If you are using a mouse, generally the left mouse button selects
- objects while the right button cancels. The exception to this is for wave
- drawing where the right button enables drawing. Dialog boxes which contain
- a Continue prompt expect you to click on the box containing the Continue
- prompt, although the right mouse button will have the same effect by
- canceling the prompt. Also, pressing Enter in this situation will cause the
- program to continue. You will notice that while a sound is being replayed
- no mouse activity is possible. It was necessary to disable mouse interrupts
- while producing sounds to avoid overloading the CPU. However, mouse control
- can be temporarily restored during sounds by holding down the right shift
- key.
-
- If no mouse is available, the arrow keys provide coarse mouse control,
- and the left shift key together with the arrow keys provides fine control.
- The left button is emulated with the Alt key, and the right button is
- replaced by the Ctrl key. For compatibility with my other mouse controlled
- programs, the Caps lock key performs the same function as Ctrl, however
- because a custom keyboard handler intercepts keyboard information, the caps
- lock key can become confused. If the Caps Lock LED ever comes on, it may be
- necessary to press Caps lock again before the program will continue.
-
- When SAMPLER is first started by typing SAMPLER or PWMSAMPL,
- information will be displayed about the default settings of the
- configuration file. When the default sound file has loaded, a dialog box
- containing all current settings will appear. Normally this is ignored by
- clicking on the continue box (or canceling with the right button or Enter),
- however, you may wish to alter an option before starting.
-
- Once you are past the initial dialog box, a plot of the current
- waveform will appear, together with several other objects. At the top of
- the screen appears a group of menu headings. Clicking on a heading will
- bring a sub-menu down. All SAMPLER functions now appear in the menu
- structure, and no keyboard commands exist. The state of the more relevant
- toggle-able functions and variables is given in a panel near the top of the
- screen, all of which may be changed from the Settings box in the menu
- (under Options). The current waveform appears in the center of the screen
- with the current start, end and loop arrows above and below. At the lower
- right is a collection of click-boxes which control the pitch of the sound
- when replayed. The vertical arrows control the octave of the sound, while
- the large and small left/right arrows alter the pitch within an octave. The
- larger arrows provide coarse control. The Reset box will restore the
- original default replay pitch, canceling the effect of other boxes. At the
- lower right of the screen are a similar set of boxes which control the
- period of the auto-timer. The auto-timer determines the rate of "auto sound
- repeat" and the speed of songs.
-
- The left, right and loop arrows determine which part of the sound
- sample is to be replayed and looped. The mouse is now used to alter these
- arrows by clicking on one and then dragging it. Normally the resolution of
- mouse control is fairly rough, however the arrows may now be placed with
- absolute precision by utilising the Zoom feature. After roughly placing an
- arrow, a region box can be marked in the waveform box by pressing the left
- mouse button and dragging. If a region is marked near the relevant arrow
- and the Zoom option is selected, a magnified view is obtained where each
- screen pixel represents one sample interval. At this point the arrow can be
- dragged to the exact position desired. Thus, it is now possible to align
- arrows such that start and end levels match, thereby avoiding audible
- "clicks" due to mismatched levels when looping.
-
- As just mentioned, a new feature known as an "active region box" can
- be marked in the wave box by pressing the left mouse button and dragging.
- The region box describes an area where some function is to be applied, such
- as mirroring, envelope scaling, cutting, pasting etc. Most functions which
- apply an operation to a specific area require a region box to be marked
- before they will be visible in the menu. In fact, all but one option under
- the Edit menu are unavailable until a region is marked. Further, the Paste
- and Mix options remain invisible until a region has been marked, cut, and a
- destination region has been marked. This "invisible" approach avoids
- confusing SAMPLER about where operations should be applied when no region
- has been specified, and avoids accidental damage to the waveform (there is
- no Undo function yet).
-
- Also, when in Zoomed mode (and no region box is active), the right
- mouse button allows direct editing of a waveform by drawing on screen.
- Using this technique, it is possible to remove clicks and pops from sounds
- where joins have been made, by drawing over them. I find this function
- extremely useful for tidying sounds after mirroring or clearing just before
- saving them to disk.
-
- The computer keyboard is now permanently in the musical instrument
- mode, ie. pressing an alpha key sounds a note at a particular pitch. The
- arrangement of keys is set to look similar to a guitar fretboard or piano
- keyboard depending of the Instrument type setting in the Settings menu. For
- the guitar fretboard option the Z key corresponds to an open low E string,
- the A key is an open A string, the Q key is an open D string, and the 1 key
- is an open G string. Alternatively, the keyboard may be considered to be 4
- rows of semitone intervals starting on the above notes.
-
- For the piano layout, the lower two rows (Z../,A..') represent F
- natural to A# with the B key representing C natural and replaying the sound
- at the original recorded pitch. The upper two rows (Q-],1-\) are similar
- but are an octave above the lower two rows with the Y key being C natural.
- Unfortunately, it is difficult to visualise the black notes initially
- because there are no missing keys like on a real piano! However, this
- arrangement may be preferable for anyone not familiar with a guitar
- fretboard.
-
-
-
- SAMPLER / PWMSAMPL Menu Functions
- ---------------------------------
-
- The following functions appear in the menu structure under the
- indicated major headings.
-
-
- ===============
- Settings ( Options )
- ===============
-
- Clicking on fields in the Settings window allows all adjustable
- program parameters to be edited. Boolean type parameters are adjusted
- by clicking on either the "Y" box or the "N" box. The box containing
- an uppercase character indicates the current setting. All other
- parameters can be edited by clicking on the field and typing in a new
- value. If a blank field is entered, the current setting remains
- unchanged. Fields in the Settings window include:
-
- Current path: allows a new sound files directory to be selected.
- A new drive prefix may also be included to allow change
- of drive.
-
- Current sound file: shows the currently active sound file. This
- field can not be altered (use the Read sound file
- option).
-
- Instrument type: allows a guitar fretboard or piano keyboard
- layout to be selected for the computer keyboard (ref.
- discussion on keyboard layout above).
-
- System type: this function selects the type of computer (XT, XT
- turbo, AT, AT turbo) being used. The faster machines will
- use a faster sample rate to give better bandwidth and
- sound quality. The speed of song playback is also
- affected by this because Pianoman's .MUS files will
- contain different duration values for different system
- speeds.
- To determine the correct selection, start with the
- appropriate setting for your PC, and if the sound is very
- low in pitch or badly distorted, try a lower setting.
- Slow XT systems may not be fast enough even for the XT
- selection. The only solution to this is to use a faster
- computer! The default machine type can be configured in
- SAMPLER.CNF. Note that PWMSAMPL chooses two PWM
- frequencies depending on this setting. If the XT setting
- causes severe noise or distortion in the PWM version,
- then your PC is just too slow for the job. Selecting the
- AT setting allows a higher PWM carrier frequency to be
- used which results in slightly better sound quality (but
- requires more processing speed).
-
- Key release: this toggles key release sensitivity. When enabled,
- releasing a key after playing a sound will terminate the
- sound. When disabled, sounds will continue after the key
- is released.
-
- Loop mode: when active, sounds will loop continuously between the
- loop pointer and right pointer. When inactive, sounds
- will be played once from the left pointer to the right
- pointer. Loop mode can be used to simulate infinite
- length sounds using finite length samples.
-
- Auto timer: toggles the use of the timer facility. The timer
- determines how long sounds will last. The main purpose
- for this is to control the speed of songs (although notes
- within songs can be different lengths). However the timer
- can be useful even when playing notes manually. For this
- situation, selecting auto timer mode means that the loop
- facility now loops to the start of the sound after the
- timer period. This is useful for repetitive percussive
- sounds because the loop rate is fixed for all notes,
- unlike the normal loop mode where the loop rate depends
- on the pitch of the note being played.
- When the auto timer is enabled, the loop setting still
- affects the sound produced. If looping is inactive, then
- for sounds shorter than the timer duration, there will be
- silence following the end of a sound until the next timer
- instance. If loop mode is active then the sound will loop
- as described previously, until the next timer instance.
-
- Trigger level: changes the minimum A/D level required to begin a
- sample operation. WARNING: if no converter is available,
- setting the trigger level above zero will almost
- certainly cause the program to enter an infinite loop,
- while waiting for a sample. Re-booting is the only way to
- recover from this situation.
-
- Sample rate: sets the sample rate for the sampling function to a
- specified number of kilohertz. Setting a low sampling
- rate allows a longer sample to be recorded, while a
- faster rate provides a wider bandwidth. If the sample
- rate is altered from the default, then the pitch for
- replay will not match the original pitch without manually
- altering the playback pitch.
-
- D/A port: allows a different I/O address to be selected for the
- D/A converted (SAMPLER only). See the discussion below on
- D/A port address in Editing the Default Configuration.
-
-
-
- ===============
- Help ( Options )
- ===============
-
- Provides very brief general help for using SAMPLER. For more
- information, read this file!
-
-
- ===============
- Directory ( File )
- ===============
-
- Provides full screen display of all files in the directory on the
- default sound files path.
-
-
- ===============
- Read sound file ( File )
- ===============
-
- Provides a directory listing of sound files in the current path
- and allows a new sound file to be selected by clicking on a file name.
- Selecting the Specify Input File box allows a file name to be typed in
- (optionally including an overriding path) and loaded. Note that small
- files will overlay only part of the sample buffer. If an active region
- (see above) has been marked, then the sound will be loaded in that
- space and truncated to fit if necessary. If no region is marked, the
- sound file will be loaded starting at the extreme left. The Read
- process can be canceled with the right mouse button, or by entering a
- blank response in the manual input box.
-
-
- ================
- Write sound file ( File )
- ================
-
- Saves the sound between the left and right pointers to a disk
- file in the current path. Note that the file name may be preceded by a
- drive and path prefix to override the current drive/path. The process
- may be canceled as described above.
-
-
- ===============
- Quit to DOS ( File )
- ===============
-
- Terminates SAMPLER and returns control to the DOS command line
- following confirmation
-
-
- ===============
- Cut ( Edit )
- ===============
-
- Once an active region has been marked (see above), the Cut option
- becomes visible. Cutting a region writes the sound information within
- the active region to a temporary clipboard file and CLEARS the marked
- region. Data in the clipboard file will remain stored until the end of
- a session, or until another Cut/Copy operation is performed. The
- clipboard data is available to the Paste and Mix functions (see
- below). Note that Cut differs from Copy in that the marked area is
- cleared (ie. silence) after the Cut operation. If you wish to move a
- sound to new position then Cut simplifies the Copy/Clear process. Be
- careful not to Cut when you really want to Copy!
-
-
- ===============
- Copy ( Edit )
- ===============
-
- Copy is similar to the Cut option, but doesn't clear the marked
- region. Note that Copy indicates data is copied to the clipboard file,
- not to the wave box. To copy an area to other positions in the wave
- box, Copy the desired area and then use a series of Pastes to place
- the data.
-
-
- ===============
- Paste ( Edit )
- ===============
-
- After Cutting or Copying data to the clipboard, that data may be
- placed in a new position in the wave box with a Paste operation. You
- must specify the destination region with the left mouse button as
- described above. The clipboard data will be truncated to fit the
- active region if necessary. You may re-paste the same data as many
- times as desired. The clipboard will only change its contents
- following another Cut/Copy or by Quitting to DOS. Pasting data several
- times after the original Copied data can be used to simulate echo
- or delay effects.
-
-
- ===============
- Mix ( Edit )
- ===============
-
- Mix is similar to Paste except that the waveform data under the
- destination region is mixed with the pasted data rather than being
- replaced by it. You will be given choices about which data should be
- scaled before the Mix is performed to avoid exceeding the maximum and
- minimum amplitudes. The Cut data which is about to be pasted can be
- halved in amplitude first, or left as it is. The existing data in the
- destination region can be halved or left alone. If the destination
- region is scaled, you can have only the data within the destination
- region scaled, or the entire sound sample scaled. If you are mixing a
- low amplitude sound in a region containing low amplitude data, scaling
- may not be necessary. If the sum of the cut and destination amplitudes
- might exceed the wave box edges, then scaling will be necessary. If
- mixing a region which is isolated from the rest of the sound sample,
- you may wish to scale just the data in the destination region and
- leave the rest of the sample alone. The circumstances of the Mix
- operation will determine the scaling choices made. If you are unsure
- about which sections need scaling, try experimenting with the various
- options on some rubbish waveforms first.
-
-
- ===============
- Mirror segment ( Edit )
- ===============
-
- Data inside the active region will become mirror image. The
- result of this is that samples will sound backwards. This is one of
- the more interesting effects available.
-
-
- ===============
- Scale envelope ( Edit )
- ===============
-
- Data inside the active region will be scaled by a specified
- factor. Constants for both ends are required, and points are scaled by
- a straight line plotted between those constants. For example, if the
- current data appears with uniform height inside the active region box,
- a decay effect can be simulated by specifying a factor of 1 for the
- left side and 0 for the right side. Note that scale factors may be
- real numbers, and that numbers greater than one may cause clipping
- distortion of the sound.
-
-
- ===============
- Clear ( Edit )
- ===============
-
- Clears (silences) sound inside the active region. You may remove
- unwanted sound by marking the relevant regions and Clearing them.
-
-
- ===============
- Zoom ( Edit )
- ===============
-
- After marking an active region and selecting the Zoom option,
- data inside the left edge of the region will be shown in magnified
- form. It is then possible to perform all normal operations on data in
- fine detail. When in Zoom mode the right mouse button allows direct
- editing of waveform data by drawing over the wave box. You can remove
- unwanted clicks and pops by drawing over them. Also, if you zoom on
- the area below or above a pointer, the pointer will be visible in the
- zoomed window and may be moved with absolute resolution. The data is
- displayed as one sample per pixel, so that pointers can be positioned
- over individual samples if desired. When positioning the loop pointer,
- the zoom feature can be used to position the loop pointer so that the
- waveform level matches the level at the right pointer thus avoiding
- any clicks when loop mode is active.
-
-
- ===============
- Sample ( Edit )
- ===============
-
- Record sound to memory at current sampling rate. This resets
- the three pointers. NOTE: the sampling function requires an A/D
- converter to be available (see previous discussion on converter
- requirements). The sampling rate will determine the available sample
- time and sampling bandwidth. This function is irrelevant for the PWM
- version.
-
-
- ===============
- Play song ( Song )
- ===============
-
- As mentioned above, this package supports Pianoman .MUS files to
- provide an automatic song mode. Pianoman is available from the PCblue
- Vol 216 and PCsig Vol 279 catalogs and is available on many Bulletin
- Boards.
- Pianoman allows real time recording of tunes from the keyboard as
- well as manual editing of tunes. I decided that using Pianoman
- externally was easier than writing an equivalent facility from
- scratch. The only problem with this system (apart from having to start
- up programs continually) is that Pianoman in not system speed
- independent. Although SAMPLER/PWMSAMPL tries to compensate for system
- speed when playing songs, you will probably find that song speed needs
- to be adjusted manually (see Auto timer in the Settings section).
- After specifying a song file using the Read songfile option and
- then selecting the Play song option, a prompt will appear. You may
- play the song once from start to finish or have it automatically
- repeat itself upon completion. While a song is playing, mouse activity
- is suspended. If you wish to alter song speed etc., holding down the
- right shift key pauses the song. The song speed can be altered by
- changing the auto timer duration from the boxes at the lower right on
- screen. The song can be terminated by pressing Ctrl (the mouse cancel
- button is disabled).
-
-
- ===============
- Read songfile ( Song )
- ===============
-
- This option allows specification of the current song file in the
- same manner as reading a sound file. The desired song file is selected
- by clicking on its name or selecting the manual entry box and typing
- the name (with optional path). Song files are assumed to be in the
- same directory as sound files.
-
-
- ===============
- Concert A ( Miscellaneous )
- ===============
-
- Produces a tone at the standard "concert A" pitch (440 Hz). This
- may be useful when preparing to sample a sound if you require it to be
- replayed at "concert pitch". If the sound is recorded using the
- default sample rate and was tuned to the reference tone, then playing
- it back from the keyboard with default tuning should produce a sound
- which is in tune with other instruments (assuming they are tuned to
- concert pitch too).
-
-
- ===============
- Monitor ( Miscellaneous )
- ===============
-
- Causes the input signal (A/D required) to be echoed to the output
- (D/A or speaker) so that the input level may set, equalisation
- adjusted etc., before actually sampling.
-
-
- ===============
- Play sound ( Play sound )
- ===============
-
- Immediately replays the current sound sample at the default
- pitch. The pitch may be altered using the tuning boxes (see above).
- This option provides a fast way to replay sounds if you just want to
- hear what they sound like.
-
-
-
-
- Editing the Default Configuration
- ---------------------------------
-
- When SAMPLER/PWMSAMPL is first run, a configuration file (SAMPLER.CNF)
- is read to determine some default settings. All defaults can be modified
- from the Settings menu box, but you may like to change the defaults
- permanently. To achieve this, a pure ASCII editor can be used, but be
- careful to maintain the correct format. There should be four lines present
- and no leading spaces on any line. The four lines are
-
- 1: Default sound files path - this determines where
- sound files will be when first run. The string may
- include a drive prefix.
-
- eg. c:\data\sounds
-
- 2: Default sound file - this sound sample file will be
- loaded when first run, and should be in the default
- sound file path.
-
- eg. bass
-
- 3: System type - this is a single letter indicating the
- type of system being used as follows:
-
- X - XT, T - XT turbo, A - AT, U - AT turbo
-
- Note that this only affects SAMPLER. PWMSAMPL will
- override system selection because all timing must
- be fixed for PWM output.
-
- 4: Parallel port number or address - this will determine
- which port SAMPLER will use for D/A output. The port may
- be described as LPTx if a printer port is to be used, or a
- decimal number which names a D/A board port address. As
- different sources of documentation give different
- information about LPT numbering, if no data appears on a
- printer port at first, try LPT1 to LPT3 until data does
- appear. Use this approach if you aren't sure which LPT
- number you are connecting to.
-
- Note that PWMSAMPL will ignore this line.
-
- 5: Default instrument (keyboard layout) - this is
- either guitar or piano.
-
-
-
-
-
-
- (C) Copyright 1989 by Rowan McKenzie
-
- Comments or suggestions for improvement
- are most welcome.
- I accept no responsibility for any injury
- or damage caused by the use of any of these files.
-
-
- Rowan McKenzie
-
- 35 Moore Ave,
- Croydon 3136
- Victoria,
- Australia
-
- Can be contacted through:
- Eastcom OPUS (830/312),
- Melbourne Data Exchange (832/360),
- The Software Bank (632/301),
- Eastwood BBS (831/343),
- Tardis BBS Vic.
- (All Vic., Australia)
- (and most other Vic Opus boards)
-